﻿using System.Collections.Generic;
using System.Linq;

using ARCHFORME.Common;

using Autofac;

namespace ARCHFORME.Core
{
    public class QueryProcessor : IQueryProcessor
    {
      

        //[DebuggerStepThrough]
        public TResult Process<TResult>(IDefineQuery<TResult> query)
        {
            //var genericArgument = typeof(query.GetType()).GetGenericArguments().FirstOrDefault();
            var handlerType = typeof(IHandleQueries<,>).MakeGenericType(query.GetType(), typeof(TResult));

            dynamic handler = Ioc.Global.Resolve(handlerType);

            return handler.Handle((dynamic)query);
        }
    }
}